///<reference path="../../service/weixin.d.ts"/>
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {GetVideoDetailService} from "../../service/http-service/getVideoDetail.service";
import {ApplicantService} from "../../service/http-service/applicant.service";
import {PayService} from "../../service/http-service/pay.service";

/**
 * Generated class for the VipPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage(
// {name: 'VipPage',
//   segment: 'vip'}

)
@Component({
  selector: 'page-vip',
  templateUrl: 'vip.html',
})
export class VipPage {

  appIdWx: string;
  timeStampWx: string;
  nonceStrWx: string;
  packageWx: string;
  signTypeWx: string;
  paySignWx: string;
  usrName: any;
  imgUrl: any;
  video={"current_price":""};

  constructor(public payService: PayService,public getVideoDetailservice:GetVideoDetailService, public applicationService: ApplicantService, public navCtrl: NavController, public navParams: NavParams) {
  }

  ionViewDidLoad() {
    var usrInfo= localStorage.getItem("options");
    //this.phone = JSON.parse(usrInfo).phone;
    this.usrName = JSON.parse(usrInfo).username;
    this.imgUrl = JSON.parse(usrInfo).header_img;
    // console.log(this.imgUrl);
    this.getVipDetail();
  }

  getVipDetail() {
    this.getVideoDetailservice.getVipInfo().subscribe(resp => {
      if (resp.data !== null && resp.code == 200) {
        this.video = resp.data;


        // console.log(resp.data);
        // localStorage.setItem("video111", resp.data);
        // console.log(this.video.url)


      } else if (resp.data !== null && resp.code == 1401) {
        console.log("errrovideo");
        this.applicationService.freshTokenn();
      }
    }, error2 => {

      console.log(error2);
    });
  }


  getPayVip() {


    console.log("11111111");
    this.getVideoDetailservice.getOrderVip().subscribe(resp => {
      if (resp.data !== null && resp.code == 200) {
        console.log(resp.data);
        this.timeStampWx = resp.data.timeStamp;
        console.log("timeStampWx");
        console.log(this.timeStampWx);
        this.appIdWx = resp.data.appId;
        this.nonceStrWx = resp.data.nonceStr;
        this.paySignWx = resp.data.paySign;
        this.packageWx = resp.data.pkg;
        // console.log("wxasdlfjalsdjkla111111111");
        console.log(this.packageWx);


        this.signTypeWx = resp.data.signType;

        this.payService.payDomain(this.appIdWx,this.timeStampWx,this.nonceStrWx,this.packageWx,this.signTypeWx,this.paySignWx);



        // this.payService.payDomain(this.appIdWx,this.timeStampWx,this.nonceStrWx,this.packageWx,this.signTypeWx,this.paySignWx);
        //
        // this.navCtrl.pop();//just for test
        // window.history.go(-1);

        // let thumbNum=document.getElementById("myDiv");
        // thumbNum.querySelector('thumb_num').innerHTML='hjh';
      } else {
        alert(resp.msg)
      }
    }, error2 => {
      alert("请检查网络连接后重试")
      console.log("error22");
    })


  }

}
